{% extends "base.html" %}
{% import "_macros.html" as macros %}
{% import "_my_wtf_macros.html" as my_wtf_macros %}

{% block title %}万屏时代OPC--战区统计列表{% endblock %}

{% block panel_heading %}
  万屏时代OPC--战区统计列表
{% endblock %}

{% block panel_body %}
    <form id="search-form" action="{{ url_for('war_zone_bp.zone_stat_list') }}" method="post" class="form" role="form">
        {{ my_wtf_macros.form_field(form.war_zone_id, div_col=4, label_col=4, field_col=7) }}
        {{ my_wtf_macros.form_field(form.date_begin, div_col=4, label_col=4, field_col=7) }}
        {{ my_wtf_macros.form_field(form.date_end, div_col=4, label_col=4, field_col=7) }}
        <div class="clearfix visible-xs-block visible-sm-block visible-md-block visible-lg-block"></div>
        <div class="pull-right btn-group">
            <button type="submit" class="btn btn-info"
                    id="experience-visit-query-btn">
                查询
            </button>
            {% if not current_user.is_agent %}
                <a
                    href="javascript:void(0);"
                    target="_blank"
                    class="btn-group btn btn-primary"
                    id="export-stat"
                >
                    导出
                </a>
            {% endif %}
        </div>
    </form>

    {% if pagination %}
    <div class="pagination">
        {{ macros.pagination_widget(pagination, 'war_zone_bp.zone_stat_list', **url_kwargs) }}
    </div>
    {% endif %}

    <table id="sms-log-table" class="table table-bordered table-hover table-condensed table-striped table-responsive">
        <thead>
            <tr>
                <th>战区</th>
                <th>日期</th>
                <th>销售额</th>
                <th>付费人数</th>
                <th>平均付费</th>
                <th>订单数</th>
                <th>发布次数</th>
                <th>抢单次数</th>
                <th>抢单人数</th>
                <th>派单人数</th>
                <th>消耗派单点</th>
                <th>锁定次数</th>
                <th>消费汇币</th>
                <th>消费人数</th>
                <th>平均消费</th>
                <th>退返汇币</th>
                <th>退返人数</th>
                <th>平均退返</th>
                <th>退返派单点</th>
                <th>退返人数</th>
                <th>总人数</th>
                <th>取关人数</th>
                <th>新增人数</th>
            </tr>
        </thead>
        <tbody>
            {% for each in data %}
            <tr>
                <td>{{ each.war_zone.name }}</td>
                <td>{{ each.date }}</td>
                <td>{{ each.sales }}</td>
                <td>{{ each.pay_people_cnt }}</td>
                {% if each.pay_people_cnt > 0 %}
                    <td>{{ (each.sales / each.pay_people_cnt) | round }}</td>
                {% else %}
                    <td>0</td>
                {% endif %}
                <td>{{ each.ro_cnt }}</td>
                <td>{{ each.published_count }}</td>
                <td>{{ each.bid_cnt }}</td>
                <td>{{ each.bid_people_cnt }}</td>
                <td>{{ each.dispatch_people_cnt }}</td>
                <td>{{ each.cost_dispatch_point }}</td>
                <td>{{ each.locked_cnt }}</td>
                <td>{{ each.cost_bid_point }}</td>
                <td>{{ each.cost_bid_people_cnt }}</td>
                {% if each.cost_bid_people_cnt > 0 %}
                    <td>{{ (each.cost_bid_point / each.cost_bid_people_cnt) | round }}</td>
                {% else %}
                    <td>0</td>
                {% endif %}
                <td>{{ each.return_bid_point }}</td>
                <td>{{ each.return_bid_people_cnt }}</td>
                {% if each.return_bid_people_cnt > 0 %}
                    <td>{{ (each.return_bid_point / each.return_bid_people_cnt) | round }}</td>
                {% else %}
                    <td>0</td>
                {% endif %}
                <td>{{ each.return_dispatch_point }}</td>
                <td>{{ each.return_dispatch_people_cnt }}</td>
                <td>{{ each.people_cnt }}</td>
                <td>{{ each.cancel_attend_cnt }}</td>
                <td>{{ each.attend_cnt }}</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>


    {% if pagination %}
    <div class="pagination">
        {{ macros.pagination_widget(pagination, 'war_zone_bp.zone_stat_list', **url_kwargs) }}
    </div>
    {% endif %}
{% endblock %}


{% block scripts %}
{{ super() }}
    <script>
        $(document).ready( function () {
            $("#export-stat").click(function () {
                var url = '{{ url_for('war_zone_bp.export_zone_stat_list') }}';
                url = url + '?' +
                    'war_zone_id=' + $('#war_zone_id').val() +
                    '&date_begin=' + $('#date_begin').val() +
                    '&date_end=' + $('#date_end').val();
                window.location.href = url;
            });
        });
    </script>
{% endblock %}
